package cn.dongjak.example.spring.security.apitoken;

import lombok.NonNull;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Service;

@Service
public class TokenServiceImpl implements TokenService {

    @Override
    public UserDetails authenticateToken(@NonNull String token) {
        if (token.equals("abcdefg")) {
            return User.builder()
                    .username("api")
                    .password("")
                    .authorities(Role.API)
                    .build();
        }

        throw new BadCredentialsException("token not found");
    }
}
